import 'package:fish_redux/fish_redux.dart';
import 'action.dart';
import 'state.dart';

Effect<BottomNavbarState> buildEffect() {
  return combineEffects(<Object, Effect<BottomNavbarState>>{
    BottomNavbarAction.onActive: _onActive,
  });
}

void _onActive(Action action, Context<BottomNavbarState> ctx) {
  final activeIndex = action.payload ?? 0;
  if (activeIndex == ctx.state.activeIndex) {
    return;
  }

  ctx.dispatch(BottomNavbarActionCreator.active(activeIndex));
}
